package com.shanyue.redwine.pay.aili;

import android.app.Activity;
import android.os.AsyncTask;
import android.os.Handler;
import android.os.Message;

import com.alipay.sdk.app.PayTask;

import java.util.Map;

/**
 * 必须传入签名后的payinfo
 * Created by Administrator on 2015/12/4.
 */
public class AlipayAsycnTask extends AsyncTask<String, Integer, String> {
    public static final int SDK_PAY_FLAG = 1;
    public static final int SDK_PAY_ERROR = 2;

    Activity activity;
    Handler payHandler;
    String payInfo;

    public AlipayAsycnTask(Activity activity, Handler payHandler, String payInfo) {
        this.activity = activity;
        this.payHandler = payHandler;
        this.payInfo = payInfo;
    }

    @Override
    protected String doInBackground(String... params) {
        try {
            // 完整的符合支付宝参数规范的订单信息
            // 构造PayTask 对象
            PayTask alipay = new PayTask(activity);
            // 调用支付接口，获取支付结果
            Map<String, String> result = alipay.payV2(payInfo, true);
            Message msg = new Message();
            msg.what = SDK_PAY_FLAG;
            msg.obj = result;
            payHandler.sendMessage(msg);
        } catch (Exception ex) {
            ex.printStackTrace();
            payHandler.sendEmptyMessage(SDK_PAY_ERROR);
        }
        return null;
    }
}
